﻿@{
    ViewBag.Title = "结算单";

}
@section styles{
    <link href="~/static/css/client.css" type="text/css" rel="stylesheet" />
    <link href="~/static/css/system.css" type="text/css" rel="stylesheet" />
    <link href="~/static/css/contract.css" type="text/css" rel="stylesheet" />
}
<style>
    a {
        text-decoration: none;
    }
</style>
<div class="layui-fluid layui-content">
    <div class="layui-title layui-clear layui-row">
        <h2 class="layui-col-md10 layui-col-sm9 layui-col-xs7">@ViewBag.Title</h2>
        <div class="layui-col-md2 layui-col-sm3 layui-col-xs5 layui-nav-item">
            <button type="button" class="layui-btn layui-btn-xs" onclick="Export()"><i class="layui-icon">&#xe63c;</i>导出</button>
        </div>
    </div>
    <div class="layui-eacher layui-row layui-clear">
        <form class="layui-clear">
            <div class="layui-form layui-clear">
                <div class="layui-col-md6 layui-col-pc7 layui-col-lg7 layui-form-group">
                    <label class="layui-form-label">
                        供应商：
                    </label>
                    <div class="layui-input-block">
                        <select class="layui-input" name="Supplier" id="Supplier">
                            <option value="" selected="selected">请选择供应商</option>
                            @foreach (var item in ViewBag.Supplier)
                            {
                                <option value="@item.SupplierName">@item.SupplierName</option>
                            }
                        </select>
                    </div>
                </div>
                <div class="layui-col-md6 layui-col-pc7 layui-col-lg7 layui-form-group">
                    <label class="layui-form-label">结算时间：</label>
                    <div class="layui-input-block">
                        <input type="text" class="layui-input" name="SettlementTime" placeholder="结算时间" id="SettlementTime" />
                    </div>
                </div>
                <div class="layui-form-group layui-col-pc1 layui-col-md2 layui-col-sm4 layui-col-xs6">
                    <label class="layui-form-label">审核状态：</label>
                    <div class="layui-input-block">
                        <select name="ExamineStatus" id="ExamineStatus">
                            <option value=" " selected="selected">全部</option>
                            <option value="0">未审核</option>
                            <option value="1">已审核</option>
                        </select>
                    </div>
                </div>
                <div class="layui-col-md1">
                    <button class="layui-btn layui-btn-sm layui-btn-normal" id="search" type="button"> 搜索 </button>
                </div>
            </div>
        </form>
    </div>
    <div class="layui-data layui-table-container">
        <table class="layui-hide layui-table" id="layui-table" lay-filter="table"></table>
    </div>
</div>
<div id="Layer_ajax" class="deploy-plus"></div>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="detail">查看明细</a>
</script>
@section scripts{
    @*
        <script src="~/Theme/js/content.min.js?v=1.0.0"></script>*@
    <script src="~/static/js/jquery.ztree.core.js" type="text/javascript"></script>
    <script src="~/static/js/jquery.ztree.excheck.js" type="text/javascript"></script>
    <script src="~/static/js/jquery.ztree.exedit.js" type="text/javascript"></script>
    <script src="~/js/main.js"></script>
    @*
        <script src="~/Theme/js/plugins/layer/laydate/laydate.js"></script>*@
    <script type="text/javascript">

        var layer,form, table, upload;
        layui.use(['form', 'layedit', 'laydate', 'tree', 'table', 'layer'], function () {
            var /*form = layui.form*/
                layedit = layui.layedit
                , laydate = layui.laydate;
            layer = layui.layer
            form = layui.form;
            table = layui.table;

            laydate.render({
                elem: '#SettlementTime'
                , type: 'date'
                , range: "~"
                , calendar: true
            });

            table.render({
                elem: "#layui-table",
                url: '@Url.Action("GetSupplierSettmentData")',
                cellMinWidth: 26,
                height: 'full-150',
                cols: [[
                    //{ type: 'checkbox' },
                    {
                        field: 'examineStatus', title: '审核状态',templet: function (d) {
                            if (d.examineStatus == 0) {
                                return 'examineStatus', "未审核";
                            } else if (d.examineStatus == 1) {
                                return 'examineStatus', "已审核";
                            } 
                        }
                    },
                    { field: 'supplierName', title: '供应商名称'},
                    {
                        field: 'settlementTime', title: '结算时间', templet: function (d) {
                            var settlementTime = new Date(d.settlementTime);
                            return 'settlementTime', top.dateFtt("yyyy-MM-dd hh:mm", settlementTime);
                        }
                    },
                    {field: 'settlementPrice', title: '结算金额'},
                    { field: 'settlementPreferentia', title: '优惠金额' },
                    { field: 'settlementAmount', title: '实际金额' },
                    { field: 'settlementUser', title: '结算人' },
                    { title: '操作', width: 213, align: 'center', toolbar: '#barDemo' }
                ]],
                id: "idTest",
                page: true,
            });

            //监听工具条
            table.on('tool(table)', function (obj) {
                var data = obj.data;
                if (obj.event === 'detail') {
                    LayerOpen("结算订单明细", "/Settlement/OrderDetails?id=" + data.id + "&examineStatus=" + data.examineStatus);
                }
            });
            $('#search').on('click', function () {
                table.reload('idTest', {
                    where: {
                        Supplier: $('#Supplier').val(),
                        SettlementTime: $('#SettlementTime').val(),
                        ExamineStatus: $('#ExamineStatus').val()
                    },
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                })

            })
        });


        $("#layui-Area").click(function () {
            $(".layui-Area .layui-Area-hide").toggleClass("layui-Area-show")
            $(this).parent(".layui-form-select").toggleClass("layui-form-selected");
        });

        $(".layui-Area").mouseleave(function () {
            $(".layui-Area .layui-Area-hide").removeClass("layui-Area-show")
        })


        $(document).ready(function () {

        });

        function Export() { 
            var Supplier = $('#Supplier').val();
            var SettlementTime = $('#SettlementTime').val();
            window.location.href = "/Settlement/ExportSettlementData?Supplier=" + Supplier + "&SettlementTime=" + SettlementTime;
        };

        function LayerOpen(title, url) {
            var open = layer.open({
                type: 2,
                title: title,
                shadeClose: true,
                shade: false,
                maxmin: true, //开启最大化最小化按钮
                area: ['780px', '500px'],
                content: url,
                success: function (layero, index) {
                    var body = layer.getChildFrame('body', index)//确定两个页面的父子关系
                },
                end: function () {
                    //销毁后重新加载
                    table.reload('idTest', {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                    })
                }
            });
        }

        function ReloadAjaxCallbackgoback(data, successInfo) {
            CommonAjaxCallback(data, function () {
                table.reload('idTest', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                })
            }, successInfo)
        }
    </script>
}
